#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
    const char *filename = "./record.txt";
    int fd = open(filename, O_RDWR | O_CREAT, 0644);
    if (fd == -1)
    {
        perror("open error:");
        exit(-1);
    }
    printf("fd = %d\n", fd);

    /*将文件的内容读到内存中*/
    char buffer[32] = {0};
    int requestBytes = sizeof(buffer) - 1;
    while (1)
    {
        int readBytes = read(fd, buffer, requestBytes);
        if (readBytes < requestBytes || requestBytes == 0)
        {
            printf("%s\n", buffer);

            break;
        }
        printf("%s\n", buffer);

        memset(buffer, 0, sizeof(buffer));
    }
    close(fd);
    return 0;
}